﻿<UserControl x:Class="LaunchPad.Core.Controls.NetworkControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:LaunchPad.Core.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DrawingBrush x:Key="RedDiagonalBrush" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,10,10" >
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Geometry="M0,25 L25,0" Brush="Red">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Red" />
                        </GeometryDrawing.Pen>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <DrawingBrush x:Key="GrayDiagonalBrush" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,10,10" >
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Geometry="M0,25 L25,0" Brush="LightGray" >
                            <GeometryDrawing.Pen>
                            <Pen Brush="Gray" />
                        </GeometryDrawing.Pen>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <DrawingBrush x:Key="CautionBrush" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,10,10" >
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Geometry="M0,25 L25,0" Brush="Yellow">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Yellow" Thickness="5" />
                        </GeometryDrawing.Pen>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <Style x:Key="BorderStyle" TargetType="{x:Type Border}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=ConnectionState}" Value="Disconnected">
                    <Setter Property="Background" Value="{StaticResource RedDiagonalBrush}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=ConnectionState}" Value="Connected">
                    <Setter Property="Background" Value="LightGray"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=ConnectionState}" Value="Unknown">
                    <Setter Property="Background" Value="{StaticResource GrayDiagonalBrush}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=ConnectionState}" Value="Armed">
                    <Setter Property="Background" Value="{StaticResource CautionBrush}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=ConnectionState}" Value="Updating">
                    <Setter Property="Opacity" Value="70"/>
                </DataTrigger>
                <!--<DataTrigger Binding="{Binding Path=IsHovered}" Value="True">
                    <Setter Property="Background" Value="#11D000FF" />
                </DataTrigger>-->
            </Style.Triggers>
        </Style>
        <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid MinHeight="14">
                            <Rectangle Name="PART_Track" Stroke="#FFEBEBEB" StrokeThickness="2">
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                        <GradientStop Offset="1" Color="#BB00FF00"/>
                                        <GradientStop Offset="0.3" Color="#BBFFFF00"/>
                                        <GradientStop Offset="0" Color="#BBFF0000"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <DockPanel Margin="0">
                                <Rectangle Name="PART_Indicator">
                                </Rectangle>
                                <Rectangle Name="Mask" MinWidth="{TemplateBinding Width}" Fill="#FFEBEBEB"/>
                            </DockPanel>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="36"/>
            <!--<RowDefinition Height="36" />-->
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Button Name="discoverButton" Click="DiscoverButtonClick" Content="Discover Network" Margin="4" HorizontalAlignment="Stretch"  />
        <!--<Button Grid.Row="1" Name="addNodeButton" Content="Add Node" Margin="4,2,4,4" HorizontalAlignment="Stretch" Click="AddNodeButtonClick" />-->
        <ListView Name="nodeListView" ItemsSource="{Binding Nodes}" Grid.Row="2" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Background="White" 
                  MouseDoubleClick="NodeListViewMouseDoubleClick" 
                  SelectionChanged="NodeListViewSelectionChanged" 
                  MouseLeftButtonDown="NodeListViewMouseLeftButtonDown"
                  MouseMove="NodeListViewMouseMove">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Border CornerRadius="2" HorizontalAlignment="Stretch" Margin="2" Style="{DynamicResource BorderStyle}" >
                        <Grid Margin="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="36"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Label Content="{Binding Path=Name}" HorizontalAlignment="Stretch" FontWeight="Bold" BorderBrush="Transparent" Background="Transparent"/>
                            <ProgressBar Value="{Binding SignalStrength}" Grid.Column="1" ToolTip="Signal Strength" Maximum="64" />
                            <Label Content="{Binding ConnectionState}" HorizontalAlignment="Left" Grid.Row="1" Background="Transparent" />
                            <Label Content="{Binding Path=SerialNumber.Value}" HorizontalAlignment="Right" Grid.Row="1" Grid.ColumnSpan="2" Background="Transparent" />
                        </Grid>
                    </Border>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</UserControl>
